package com.csnf.controller;

import com.csnf.pojo.Catogery;
import com.csnf.pojo.Result;
import com.csnf.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/category")
@CrossOrigin
public class CategoryController {

    @Autowired
    CategoryService categoryService;

    @RequestMapping("/findAll")
    public Result findAll(){
        List<Catogery> lst =categoryService.findAll();
        return Result.success(lst);
    }

    @RequestMapping("/delete")
    public Result deleteById(Integer id){
        Integer i = categoryService.deleteById(id);
        if (i>0){
            return Result.success();
        }else{
            return Result.error("删除失败!");
        }
    }
}
